package util;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

/**
 * @author ：hzs
 * @date ：Created in 2021/1/9 14:41
 * @description：
 * @modified By：
 * @version: $
 */
public class StopWordUtil {

    private final static String STOPWORDS_EN = "stopwordsEN.txt";

    private final static String NOUN_PHRASE_STOPWORDS = "noun_phrase_stopwords.txt";

    public static Set<String> getStopWords() {
        return getWords(NOUN_PHRASE_STOPWORDS);
    }

    public static Set<String> getStopWordsEN() {
        return getWords(STOPWORDS_EN);
    }

    private static Set<String> getWords(String resource) {
        Set<String> stopWordSet = new HashSet<>();
        String path = StopWordUtil.class.getClassLoader().getResource(resource).getPath();
        try(BufferedReader br = new BufferedReader(new InputStreamReader(
                new FileInputStream(path)))) {
            for (String line = br.readLine(); line != null; line = br.readLine()) {
                stopWordSet.add(line);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return stopWordSet;
    }
}
